A long time, usually defining how late
someone might stay up at night or out at bars, nightclubs,
discos etc.
The origin of the phrase goes back to
a time when people were familiar with the time cows came home
(in the very
early morning... 4 - 5 a.m.) because they wanted to be
milked.